#!/bin/bash

BASE_PATH=`pwd`

NETWORK_NAME="secloud-network"

SERVICE_NAME="chainmaker-ca"
SERVICE_VERSION="2.2.0"

# registry path
REGISTRY="svr01:5000"

mprint() {
  echo -e $(TZ=UTC-8 date +'%Y-%m-%dT%H:%M:%SZ') $*
}

clean_up() {
  mprint "clean up"
  if [[ $(docker images -q -f dangling=true | wc -l) -gt 0 ]]; then
    docker rmi $(docker images -q -f dangling=true)
  fi
}

docker build . --tag=$REGISTRY/$SERVICE_NAME:$SERVICE_VERSION
docker push $REGISTRY/$SERVICE_NAME:$SERVICE_VERSION

for id in `docker ps -q -a --filter name=$SERVICE_NAME`; do
  docker rm -f $id
done

clean_up
